package com.rsk.api;


import java.util.List;
import java.util.Map;

import javax.ws.rs.QueryParam;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.rsk.aop.ParamCheck;
import com.rsk.api.common.ReturnUtils;
import com.rsk.service.SysMenuService;
import com.rsk.utils.result.Result;
import com.rsk.utils.result.ResultBuilder;
import com.rsk.utils.result.ResultCode;

@RestController
@RequestMapping(value="/sys/menu")
public class SystemMenuApi {
	
	@Reference(interfaceClass = SysMenuService.class, protocol = "dubbo")
	private SysMenuService sysMenuService;
	
	
	//@RequiresPermissions("sys_menus:save")
	@PostMapping(value="/saveSysMenu" )
	public Result<String> saveSysMenu(@QueryParam("menuName") @ParamCheck(notNull=true) String menuName,
		   							  @QueryParam("menuUrl") @ParamCheck(notNull=true) String menuUrl,
		   							  @QueryParam("sort") @ParamCheck(notNull=true) Integer sort,
		   							  @QueryParam("pId") @ParamCheck(notNull=true) Long pId,
		   							  @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysMenuService.saveSysMenu(menuName, menuUrl, pId, sort, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	//@RequiresPermissions("sys_menus:update")
	@PostMapping(value="/updateSysMenu" )
	public Result<String> updateSysMenu(@QueryParam("id") @ParamCheck(notNull=true) Long id,
										@QueryParam("menuName") @ParamCheck(notNull=true) String menuName,
										@QueryParam("menuUrl") @ParamCheck(notNull=true) String menuUrl,
										@QueryParam("sort") @ParamCheck(notNull=true) Integer sort,
									    @RequestHeader("Authorization") String Authorization){
		//数据校验
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysMenuService.updateSysMenu(id, menuName, menuUrl, sort, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}
	
	
	
	//@RequiresPermissions("sys_menus:del")
	@PostMapping(value="/delSysMenu" )
	public Result<String> delSysDept(@QueryParam("id") @ParamCheck(notNull=true) Long id,
									 @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		Long operatorUser = 123L;
		int i = sysMenuService.delSysMenu(id, operatorUser);
		return ReturnUtils.returnDataByOne(i);
	}

	@SuppressWarnings("rawtypes")
	@PostMapping(value="/selectMenus" )
	public Result<List<Map>> selectMenus(@QueryParam("menuName") String menuName,
										 @QueryParam("menuUrl") String menuUrl,
										 @RequestHeader("Authorization") String Authorization){
		//String operatorUser = JwtUtil.getClaim(Authorization, "account");
		List<Map> list = sysMenuService.selectMenu(menuName, menuUrl);
		return ResultBuilder.success(list,ResultCode.SUCCESS);
	}
}
